<?php
// +----------------------------------------------------------------------+
// | Author:  Evgeny Leontev <eleontev@gmail.com>                         |
// | Copyright (c) 2005 Evgeny Leontev                                    |
// +----------------------------------------------------------------------+
// | This source file is free software; you can redistribute it and/or    |
// | modify it under the terms of the GNU Lesser General Public           |
// | License as published by the Free Software Foundation; either         |
// | version 2.1 of the License, or (at your option) any later version.   |
// |                                                                      |
// | This source file is distributed in the hope that it will be useful,  |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
// | Lesser General Public License for more details.                      |
// +----------------------------------------------------------------------+

class CommonEntryView
{	

	// LIST // -----------------------
	
	function &parseCategoryRoles($category_roles, $msg) {	
		foreach($category_roles as $category_id => $data) {
			foreach($data as $k => $v) {
				$category_roles[$category_id][$k] = sprintf('%s (%s)', $v, $msg['category_msg']);
			}
		}
		
		return $category_roles;
	}	
	
	
	function getPrivateMsg($entry_roles, $category_roles) {
		$roles_msg = '';
		
		if($entry_roles && $category_roles) { 
			$roles_msg = ' - ' . implode('<br> - ', array_merge($entry_roles, $category_roles));
		} elseif($entry_roles) {
			$roles_msg = ' - ' . implode('<br> - ', $entry_roles);
		} elseif($category_roles) {
			$roles_msg = ' - ' . implode('<br> - ', $category_roles);
		}
		
		return $roles_msg;
	}
	
	
	function getColorsAndRolesMsg($row, $msg) {
		$data = array();
		
		if($row['private'] && $row['category_private']) { 
			$data['image_color'] = 'blue';
			$data['private1_msg'] =  sprintf('%s - (%s, %s)', $msg['private_msg'], $msg['entry_msg'], $msg['category_msg']); 
		} else { 
			if($row['private']) {
				$data['image_color'] = 'orange';
				$data['private1_msg'] =  sprintf('%s %s', $msg['private_msg'], $msg['entry_msg']); 
			} else {
				$data['image_color'] = 'red';
				$data['private1_msg'] =  sprintf('%s %s', $msg['private_msg'], $msg['category_msg']);
			}
		}
		
		return $data;
	}	



	// FORM // -----------------------

	function ajaxGetCategoryRoles($category_id, $manager) {
		
		$msg = CommonEntryView::getPrivateCategoryMsg($manager, $category_id);

		$objResponse = new xajaxResponse();
		$objResponse->setCharEncoding($this->encoding);
		
		//$objResponse->addAlert($category_id);
		//$objResponse->addAlert($roles);
		
		$objResponse->addAssign("category_info", "innerHTML", $msg);
		$objResponse->addAssign("category_info_1", "innerHTML", $msg);
	
		return $objResponse;	
	}
	
	
	function getPrivateCategoryMsg(&$manager, $category_id) {
		
		$roles = false;
		$msg = '';
		$is_private = $manager->isPrivate($category_id);
		
		if($is_private) {
			$roles = $manager->getMemberRoleById($category_id, true);
			$roles = ($roles) ? implode(', ', $roles[$category_id]) : '';

			$str = '<span style="color:#cc0000;"><b>%s</b></span>';
			$msg = sprintf($str, $this->msg['private_category_msg']);
			
			if($roles) {
				$str = ' - <b>%s:</b> (%s)';
				$msg .= sprintf($str, $this->msg['roles_msg'], $roles);
			} else {
				$msg .= sprintf(' - <b>%s</b>', $this->msg['no_roles_msg']);
			}
		}
		
		return $msg;	
	}		
}
?>